package cn.jx.easyplayer;

import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.widget.RelativeLayout;

import cn.jx.easyplayerlib.view.EasyVideoView;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getSimpleName();
    private Handler mainHandler = new Handler();
    private EasyVideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         videoView = (EasyVideoView) findViewById(R.id.easy_video_view);
        String folderurl = Environment.getExternalStorageDirectory().getPath();
        String inputurl = folderurl + "/input.mp4";
//        videoView.setVideoPath("rtmp://live.hkstv.hk.lxdns.com/live/hks");
//        videoView.setVideoPath("rtmp://114.67.224.129/myapp/stream");
        videoView.setVideoPath(inputurl);

    }

    @Override
    protected void onPause() {
        super.onPause();
        togglePaused();
    }

    public void onResolutionChange(final int width, final int height) {
        Display display = getWindowManager().getDefaultDisplay();
        final int displayWidth = display.getWidth();
        mainHandler.post(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoView.getLayoutParams();
                params.height = displayWidth * height / width;
                videoView.setLayoutParams(params);
            }

        });


    }

    public native void togglePaused();
}
